﻿package birdry.utils	{
	
	//	birdry.utils.FilterUtil;
	
	import flash.filters.ColorMatrixFilter;
	import flash.filters.ConvolutionFilter;
	import flash.filters.DropShadowFilter;
	import flash.filters.BlurFilter;
	
	public class FilterUtil	{
		
		public static function dropShadow( distance:Number=4, angle:Number = 45): DropShadowFilter	{
			return new DropShadowFilter(distance, angle);
		}
		
		public static function blur( blurX:Number = 4, blurY:Number = 4, quality:uint = 1): BlurFilter	{
			return new BlurFilter(blurX, blurY, quality);
		}
		
		/**
		* 밝기조절 필터
		* @param	nValue	:	(default = 1 ~	)
		* @return
		* ex -> object.filters = [FilterUtil.negaTive()];
		*/
		public static function bright( nValue:Number ): ColorMatrixFilter	{
			var _return:ColorMatrixFilter = new ColorMatrixFilter([
													 nValue, 0, 	0, 		0, 0, 
													 0, 	nValue, 0, 		0, 0, 
													 0, 	0, 		nValue, 0, 0, 
													 0, 	0, 		0, 		1, 0
													 ]);
			return _return;
		}
		
		
		/**
		* 채도 필터	
		* @param	nValue	:	(default = 1 ~	)
		* @return
		*/
		public static function saturation(nValue:Number): ColorMatrixFilter 	{ 
			var nRed:Number = 0.3086;
			var nGreen:Number = 0.6094;
			var nBlue:Number = 0.0820;
			var nA:Number = (1 - nValue) * nRed + nValue;
			var nB:Number = (1 - nValue) * nGreen; 
			var nC:Number = (1 - nValue) * nBlue;
			var nD:Number = (1 - nValue) * nRed;
			var nE:Number = (1 - nValue) * nGreen + nValue;
			var nF:Number = (1 - nValue) * nBlue;
			var nG:Number = (1 - nValue) * nRed;
			var nH:Number = (1 - nValue) * nGreen;
			var nI:Number = (1 - nValue) * nBlue + nValue;
			var _return:ColorMatrixFilter = new ColorMatrixFilter([
													 nA, nB, nC, 0, 0, 
													 nD, nE, nF, 0, 0, 
													 nG, nH, nI, 0, 0, 
													 0, 0, 0, 1, 0
													 ]);
			return _return;
		}
		
		

		/**
		* 대조변경 필터	
		* @param	nValue	:	(default = 1 ~	)
		* @return
		*/
		public static function contrast(nValue:Number): ColorMatrixFilter	 {
			nValue /= 10;
			var nScale:Number = nValue * 11;
			var nOffset:Number = 63.6 - (nValue * 698.5);
			var _return:ColorMatrixFilter = new ColorMatrixFilter([
													 nScale, 	0, 		0, 		0, 	nOffset, 
													 0, 		nScale, 0, 		0, 	nOffset, 	
													 0,			0, 		nScale, 0, 	nOffset, 	
													 0, 		0, 		0, 		1, 	0]
													);
			return _return;
		}
		
		
		/**
		* 그레이스케일 필터
		* @return
		*/
		public static function graySclae(): ColorMatrixFilter	{
			var _return:ColorMatrixFilter = new ColorMatrixFilter([
													 0.3086, 	0.6094, 0.0820, 0, 0, 
													 0.3086, 	0.6094, 0.0820, 0, 0, 
													 0.3086, 	0.6094, 0.0820, 0, 0, 
													 0, 		0, 		0, 		1, 0
													 ]);
			return _return;
		}
		


		/**
		* 네거티브 필터
		* @return
		*/
		public static function negaTive(): ColorMatrixFilter	{
			var _return:ColorMatrixFilter = new ColorMatrixFilter([
													 -1, 0, 0, 	0, 255, 
													 0, -2, 0, 	0, 255, 
													 0, 0, 	-1, 0, 255, 
													 0, 0, 	0, 	1, 0
													 ]);
			return _return;
		}
		

		/**
		* 적청반전 필터
		* @return
		*/
		public static function redBlue(): ColorMatrixFilter	{
			var _return:ColorMatrixFilter = new ColorMatrixFilter();
			_return.matrix = new Array(
											0,	0,	1,	0,	0,
											0,	1,	0,	0,	0,
											1,	0,	0,	0,	0,
											0,	0,	0,	1,	0);
			return _return;
		}
		

		/**
		* 세피아 필터
		* @return
		*/
		public static function sephia(): ColorMatrixFilter	{
			var _return:ColorMatrixFilter = new ColorMatrixFilter();
			_return.matrix = new Array(
											1/2,	1/2,	1/2,	0,	0,
											1/3,	1/3,	1/3,	0,	0,
											1/4,	1/4,	1/4,	0,	0,
											0,  	0,  	0,		1,	0
										);
			return _return;
		}
		
	
	}	// class
}	// package